package evcs

import (
	"errors"
	"evtest/util"
	"strconv"
	"strings"
)

type EvcsRsp struct {
	Ret  int
	Msg  string
	Data string
	Sig  string
}

func (evcsRsp *EvcsRsp) VerifyNoticeResult(hmacKey string) error {
	strToBeSigned := strconv.Itoa(evcsRsp.Ret) + evcsRsp.Msg + evcsRsp.Data
	if evcsRsp.Sig != strings.ToUpper(util.Hmac(hmacKey, strToBeSigned)) {
		return errors.New("返回值签名不匹配")
	}
	return nil
}

func (evcsRsp *EvcsRsp) Decrypt(aesKey string, ivStr string) ([]byte, error) {
	jsonStr, err := util.AESBase64Decrypt(evcsRsp.Data, aesKey, ivStr)
	return jsonStr, err
}

type QueryTokenResponse struct {
	OperatorId         string
	SuccStat           int
	AccessToken        string
	TokenAvailableTime int
	FailReason         int
}

func (queryTokenResponse *QueryTokenResponse) Reset() {
	queryTokenResponse.OperatorId = ""
	queryTokenResponse.SuccStat = 0
	queryTokenResponse.AccessToken = ""
	queryTokenResponse.TokenAvailableTime = 0
	queryTokenResponse.FailReason = 0
}

type StationInfoResponse struct {
	PageNo       int           `json:"PageNo"`
	PageCount    int           `json:"PageCount"`
	ItemSize     int           `json:"ItemSize"`
	StationInfos []StationInfo `json:"StationInfos"`
}

type StationInfo struct {
	StationID        string          `json:"StationID"`
	OperatorID       string          `json:"OperatorID"`
	EquipmentOwnerID string          `json:"EquipmentOwnerID"`
	StationName      string          `json:"StationName"`
	CountryCode      string          `json:"CountryCode"`
	AreaCode         string          `json:"AreaCode"`
	Address          string          `json:"Address"`
	ServiceTel       string          `json:"ServiceTel"`
	StationType      int             `json:"StationType"`
	StationStatus    int             `json:"StationStatus"`
	ParkNums         int             `json:"ParkNums"`
	StationLng       float32         `json:"StationLng"`
	StationLat       float32         `json:"StationLat"`
	Construction     int             `json:"Construction"`
	EquipmentInfos   []EquipmentInfo `json:"EquipmentInfos"`
}

type EquipmentInfo struct {
	EquipmentID    string          `json:"EquipmentID"`
	ManufacturerID string          `json:"ManufacturerID"`
	EquipmentModel string          `json:"EquipmentModel"`
	EquipmentType  int             `json:"EquipmentType"`
	Power          float32         `json:"Power"`
	ConnectorInfos []ConnectorInfo `json:"ConnectorInfos"`
}

type ConnectorInfo struct {
	ConnectorID        string  `json:"ConnectorID"`
	ConnectorType      int     `json:"ConnectorType"`
	VoltageUpperLimits int     `json:"VoltageUpperLimits"`
	VoltageLowerLimits int     `json:"VoltageLowerLimits"`
	Current            int     `json:"Current"`
	Power              float32 `json:"Power"`
	NationalStandard   int     `json:"NationalStandard"`
}
